package com.mobile.business.grid;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.LockMode;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.mobile.gridUtil.FilterBean;
import com.mobile.gridUtil.GridFilter;
import com.mobile.struts.action.tools.AssociateTableInfo;
import com.mobile.tools.PageBean;
/**
 * 简单的需要事物处理的业务操作
 * @author huangfeng
 *
 */
public interface IBaseBusiness {
	String BEAN_ID="baseBusiness";
	String save(Object o);
	String save(String entityName,Object entity);
	void saveCollection(Collection entities);
	void saveCollection(String entityName,Collection entities);
	void saveOrUpdate(Object entity);
	void saveOrUpdate(String entityName, Object entity);
	void saveOrUpdateAll(Collection entities);
	Object merge(Object entity);
	Object merge(String entityName, Object entity);
	void mergeCollection(Collection entities);
	void mergeCollection(String entityName,Collection entities);
	/**
	 * 如果没有此持久化对象，就保存，如果又把非空的数据添加到此数据中
	 * @param uniqueCode		持久化数据id
	 * @param entity			要持久化的对象
	 * @return
	 */
	Object mergeNotNull(String uniqueCode,Object entity);
	void update(Object entity);
	void update(Object entity, LockMode lockMode);
	void update(String entityName, Object entity);
	void update(String entityName, Object entity, LockMode lockMode);
	void delete(Object entity);
	void delete(Object entity, LockMode lockMode);
	void delete(String entityName, Object entity);
	void delete(String entityName, Object entity, LockMode lockMode);
	void deleteAll(Collection entities);
	/**
	 * 删除多条记录
	 * @param uniqueCodes
	 */
	void deleteById(Class clazz,String[] uniqueCodes);
	void deleteById(Class clazz,String uniqueCode);
	List getAllList(Object pojo);
	List findByExample(Object o);
	List findByExample(Object o,String[] orders);
	List findByExample(Object o,List<Order> orders);
	Object findById(Class clazz,String id);
	List findByCriteria(DetachedCriteria criteria);
	List findByCriteria(DetachedCriteria criteria,
            int firstResult,
            int maxResults);
	Object get(Class entityClass, Serializable id) ;
	Object get(Class entityClass, Serializable id, LockMode lockMode);
	Object get(String entityName, Serializable id)  ;
	Object get(String entityName, Serializable id, LockMode lockMode)  ;
	Object load(Class entityClass, Serializable id)  ;
	Object load(Class entityClass, Serializable id, LockMode lockMode)  ;
	void load(Object entity, Serializable id) ;
	Object load(String entityName, Serializable id)  ;
	Object load(String entityName, Serializable id, LockMode lockMode)  ;
	/**
	 * 分页
	 * @param start 			跳转的页数（开始的页数）
	 * @param pageSize			一页有多少行
	 * @param pojo				用来创建org.hibernate.criterion.Example的pojo类
	 * @param gridFilterList	查询条件树组
	 * @return
	 */
	public PageBean getPageRecord(int start,int pageSize,Object pojo,List<GridFilter> gridFilterList);
	/**
	 * grid过滤
	 * @param start
	 * @param pageSize
	 * @param form
	 * @param map
	 * @return
	 */
	public PageBean getPageBean(int start,int pageSize,Object pojo,Map<String,FilterBean> map);
	/**
	 * grid过滤
	 * @param start
	 * @param pageSize
	 * @param form
	 * @param map
	 * @param list
	 * @return
	 */
	public PageBean getPageBean(int start,int pageSize,Object pojo,Map<String,FilterBean> map,List<AssociateTableInfo> list);
	/**
	 * 获得所有数据
	 * @param cl				域模型的类
	 * @param gridFilterList	要过滤的列表值
	 * @return					列表
	 */
	public List getAllList(Class cl,List<GridFilter> gridFilterList);
	/**
	 * 获得所有数据
	 * @param pojo				域模型的类
	 * @param gridFilterList	要过滤的列表值
	 * @return					列表
	 */
	public List getAllList(Object pojo,List<GridFilter> gridFilterList);
	/**
	 * 获得所有数据
	 * @param cl				域模型的类
	 * @param map				需要处理的的map数据
	 * @return					列表
	 */
	public List getAllList(Class cl,Map<String,FilterBean> map);
	/**
	 * 获得所有数据
	 * @param map				需要处理的的map数据
	 * @return					列表
	 */
	public List getAllList(Object pojo,Map<String,FilterBean> map);
	/*
	 * ibatis
	 */
	public Object queryForList(String statementName);
}
